package com.ssmdemo.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.ssmdemo.aop.bean.LoginUser;
import com.ssmdemo.aop.bean.PermissionCode;
import com.ssmdemo.pojo.Emp;
import com.ssmdemo.pojo.User;
import com.ssmdemo.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/getEmp")
public class GetEmpList {

    @Autowired
    EmpService empService;

    @RequestMapping("/getEmpList")
    @PermissionCode(value = "emp:list")
    public String getEmpList(Page page,Model model){
        page=empService.selectPage(page);
        model.addAttribute("url","getEmpList");
        model.addAttribute("page",page);
        return "emp/empList";
    }

    @RequestMapping("/toAddEmp")
    public String toAddEmp(){
        return "emp/addEmp";
    }
    @RequestMapping("/toUpdateEmp/{id}")
    public String toUpdateEmp(@PathVariable Integer id,Model model){
        Emp emp=empService.selectById(id);
        model.addAttribute("emp",emp);
        return "emp/updateEmp";
    }

    @RequestMapping("/getAddEmp")
    @ResponseBody
    @LoginUser(saveParamObject = true)
    public String getAddEmp(Emp emp){
        System.out.println(emp);
//        empService.insert(emp);
//        return "redirect:getEmpList";
        return "可以OK";
    }
    @RequestMapping("/getUpdateEmp")
    public String getUpdateEmp(Emp emp){
        empService.updateById(emp);
        return "redirect:getEmpList";
    }

    @RequestMapping("/bacthDelectEmp")
    public String bacthDelectEmp(@RequestParam("d[]") List d){

        empService.deleteBatchIds(d);
        return "redirect:getEmpList";
    }


    @RequestMapping("/test2")
    @ResponseBody
    @LoginUser(saveParamObject = false)
    public String test2(User user, Map map){

        System.out.println("user = " + user + ", map = " + map);

        return "ok了";
    }

}
